﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CRConsult.Models
{
    public class catRepository
    {
        /// <summary>
        /// 获取新闻类别列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<tb_NewsCat> getCategory(int id)
        {
            using (LingHealEntities db = new LingHealEntities())
            {
                var items = db.tb_NewsCat.Where(i => i.CatID == id);
                return items.ToList();
            }
        }

        /// <summary>
        /// 添加新闻类别列表
        /// </summary>
        /// <param name="item"></param>
        public void insertCat(tb_NewsCat item)
        {
            using (LingHealEntities db = new LingHealEntities())
            {
                db.AddTotb_NewsCat(item);
                db.SaveChanges();
            }
        }

        /// <summary>
        /// 更新新闻列别
        /// </summary>
        /// <param name="item"></param>
        public void updateCat(tb_NewsCat item)
        {
            using (LingHealEntities db = new LingHealEntities())
            {
                var originitem = db.tb_NewsCat.FirstOrDefault(i => i.CatID == item.CatID);
                originitem.CatCode = item.CatCode;
                originitem.CatName = item.CatName;
                db.SaveChanges();
            }
        }


        /// <summary>
        /// 删除新闻类别
        /// </summary>
        /// <param name="id"></param>
        public void delCat(int id)
        {
            using (LingHealEntities db = new LingHealEntities())
            {
                db.DeleteObject(db.tb_NewsCat.Where(i => i.CatID == id));
                db.SaveChanges();
            }
        }

        


    }
}